//
//  MyAllZCViewController.m
//  CarTown
//
//  Created by xionghao on 15/8/27.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "MyAllZCViewController.h"
#import "BottomBar.h"
#import "ZTCarTableViewCell.h"
#import "MyZTCarDetailTableViewController.h"
#import <MJRefresh.h>
#import "Puser.h"
#import "ZCModel.h"
#import "UserInfoUpdateResde.h"
#import "SearchMode.h"
#import "SearchTableViewCell.h"
#import "ZCSearchMode.h"
#import "ZCSearchCount.h"
#import "MyZTTableViewController.h"
#import "CZSearchBar.h"
#import "SearchTableViewController.h"
#import "History.h"
@interface MyAllZCViewController ()
<UITableViewDataSource,UITableViewDelegate,BottomBarBtnClickDelegate,UISearchBarDelegate,UISearchDisplayDelegate,SearchTableViewDelegate,UIAlertViewDelegate,BottombarDataSource>{
    BOOL _isedting;
    BOOL _candelete;
    BOOL _isshowsearch;
}
@property (nonatomic,strong) BottomBar *bottombar;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) CZSearchBar *search;
@property (nonatomic,strong) NSMutableArray *datalist;
@property (nonatomic,strong) UISearchDisplayController *searchController;
@property (nonatomic,strong) NSMutableArray *searcharray;
@property (nonatomic,strong) Puser *user;

@property (nonatomic,copy) NSString *keyword;
@property (nonatomic,copy) NSString *cat_name;
@property (nonatomic,strong) UIButton *clearbtn;
@end

@implementation MyAllZCViewController
+(instancetype)Viewcontroller{
    MyAllZCViewController *myallvc=[[MyAllZCViewController alloc]init];
    myallvc.hidesBottomBarWhenPushed=YES;
    return myallvc;
}
-(void)searchDidCancelClick{
    _isshowsearch=NO;
    [self setNeedsStatusBarAppearanceUpdate];
}
-(void)searchCilck:(PUSHTYPE)type WithString:(NSString *)string{
    _isshowsearch=NO;
    [self setNeedsStatusBarAppearanceUpdate];
    if (type==PUSHTYPEZTCAR) {
        self.keyword=string;
        self.search.text=self.keyword;
        self.clearbtn.hidden=NO;
        [self.tableView.header beginRefreshing];
    }
}

-(NSInteger)numberofBottobarcount:(BottomBar *)bottombar{
    return self.datalist.count;
}

-(NSMutableArray *)datalist{
    if ( _datalist==nil) {
        _datalist=[NSMutableArray array];
    }
    return  _datalist;
}
-(NSMutableArray *)searcharray{
    if ( _searcharray==nil) {
        _searcharray=[NSMutableArray array];
    }
    return  _searcharray;
}
-(Puser *)user{
    if (_user==nil) {
        _user=[Puser getUser];
    }
    return _user;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.contentInset=UIEdgeInsetsMake(0, 0, 56, 0);
    self.navigationItem.title=@"我的展车";
    [self setuptableView];
    if (!self.isFromSearch) {
        [self setupRight:NO];
    }
    UIButton *backbtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [backbtn setImage:[UIImage imageNamed:@"back_ico"] forState:UIControlStateNormal];
    CGSize backsize=backbtn.currentImage.size;
    backbtn.frame=CGRectMake(0, 0, backsize.width, backsize.height);
    
    [backbtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:backbtn];
    [self setupsearch];
    if (self.isFromSUS) {
        NSMutableArray *vcarray=[[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
        [vcarray removeObjectAtIndex:self.navigationController.viewControllers.count-2];
        [vcarray removeObjectAtIndex:self.navigationController.viewControllers.count-3];
        self.navigationController.viewControllers = vcarray;
    }
    
    // Do any additional setup after loading the view.
}

-(void)back{
    for (UIViewController *vc in self.navigationController.viewControllers) {
        if ([vc isKindOfClass:[MyZTTableViewController class]]) {
            [self.navigationController popToViewController:vc animated:YES];
            return;
        }
    }
    MyZTTableViewController *vc=[MyZTTableViewController viewcontroller];
    vc.isFromALL=YES;
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)BottomBarAllclick:(BottomBar *)bottombar{
    for (ZCModel *mode in self.datalist) {
        mode.ischecked=bottombar.allselected;
    }
    [self.tableView reloadData];
}


-(void)deleteZC{
    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
    hud.labelText=@"正在操作";
    hud.margin = 10.f;
    hud.removeFromSuperViewOnHide = YES;
    NSMutableDictionary *params=[NSMutableDictionary dictionary];
    params[@"action"]=@"del_display";
    NSInteger power=[self.user.power integerValue];
    if (power<5) {
        params[@"type"]=@"person";
        params[@"user_id"]=self.user.user_id;
    }else{
        params[@"type"]=@"company";
        params[@"user_id"]=self.user.com_id;
    }
    
    NSMutableArray *IDarray=[NSMutableArray array];
    for (ZCModel *mode in self.datalist) {
        if (mode.ischecked) {
            [IDarray addObject:mode.ID];
        }
    }
    params[@"dis_id"]=[NSString DataTOjsonString:IDarray];
    
    [PostUitls Post:myzturl parameters:params success:^(id response) {
        UserInfoUpdateResde *resdmode=[UserInfoUpdateResde resdeWithDict:response];
        if ([resdmode.state integerValue]==400) {
            [self.tableView.header beginRefreshing];
            _candelete=NO;
            self.bottombar.btnenable=_candelete;
            self.bottombar.allselected=_candelete;
        }
        hud.labelText=resdmode.msg;
        hud.mode = MBProgressHUDModeText;
        [hud hide:YES afterDelay:1];
    } failure:^(NSError *error) {
        hud.labelText=@"网络错误";
        hud.mode = MBProgressHUDModeText;
    }];

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==0) {
        return;
    }else{
    [self deleteZC];
    }
}

-(void)showalert{
    UIAlertView *alret=[[UIAlertView alloc]initWithTitle:@"提示" message:@"确认删除么?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alret show];
}



-(void)BottomBar:(BottomBar *)bottombar otherbtnClick:(NSInteger)index{
    if (index==0) {
        [self showalert];
    }else{
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"正在操作";
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        NSMutableDictionary *params=[NSMutableDictionary dictionary];
        params[@"action"]=@"ref_display";
        NSInteger power=[self.user.power integerValue];
        if (power<5) {
            params[@"type"]=@"person";
            params[@"user_id"]=self.user.user_id;
        }else{
            params[@"type"]=@"company";
            params[@"user_id"]=self.user.com_id;
        }
        
        NSMutableArray *IDarray=[NSMutableArray array];
        for (ZCModel *mode in self.datalist) {
            if (mode.ischecked) {
                [IDarray addObject:mode.ID];
            }
        }
        params[@"dis_id"]=[NSString DataTOjsonString:IDarray];
        
        [PostUitls Post:myzturl parameters:params success:^(id response) {
            UserInfoUpdateResde *resdmode=[UserInfoUpdateResde resdeWithDict:response];
            if ([resdmode.state integerValue]==400) {
                [self.tableView.header beginRefreshing];
                _candelete=NO;
                self.bottombar.btnenable=_candelete;
                self.bottombar.allselected=_candelete;
            }
            hud.labelText=resdmode.msg;
            hud.mode = MBProgressHUDModeText;
            [hud hide:YES afterDelay:1];
        } failure:^(NSError *error) {
            NSLog(@"%@",error);
            
            hud.labelText=@"网络错误";
            hud.mode = MBProgressHUDModeText;
        }];
    }

}

-(void)setuptableView{
    MJRefreshNormalHeader *header=[MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refresh)];
    self.tableView.header=header;
    self.tableView.header.automaticallyChangeAlpha=YES;
    MJRefreshBackNormalFooter *footer=[MJRefreshBackNormalFooter footerWithRefreshingTarget: self refreshingAction:@selector(loadmoredata)];
    self.tableView.footer=footer;
   
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
     [self.tableView.header beginRefreshing];
}

-(void)refresh{
    NSMutableDictionary *params=[NSMutableDictionary dictionary];
    
    if (self.isFromSearch) {
        if ([self.user_id integerValue]!=0) {
            params[@"type"]=@"person";
            params[@"user_id"]=self.user_id;
        }else{
            params[@"type"]=@"company";
            params[@"user_id"]=self.com_id;
        }
    }else{
    
  
    NSInteger power=[self.user.power integerValue];
    
    if (power<5) {
        params[@"type"]=@"person";
        params[@"user_id"]=self.user.user_id;
    }else{
        params[@"type"]=@"company";
        params[@"user_id"]=self.user.com_id;
//        if (power==8) {
//            params[@"pid"]=self.user.parent_id;
//        }
    }
    }
    
    if (self.keyword) {
        self.search.text=self.keyword;
        params[@"keyword"]=self.keyword;
        if (self.cat_name) {
            params[@"cat_name"]=self.cat_name;
        }
        params[@"action"]=@"display_search";
    }else{
    if (self.brand_id) {
        params[@"brand_id"]=self.brand_id;
    }
        params[@"action"]=@"display_list";
    }
    params[@"num"]=Kpagesize;
    [PostUitls Post:myzturl parameters:params success:^(id response) {
        NSDictionary *dict=response;
        NSNumber *state=dict[@"state"];
        if ([state integerValue]==400) {
            [self.datalist removeAllObjects];
            
            NSDictionary *data=dict[@"data"];
            
            [ZCModel setupReplacedKeyFromPropertyName:^NSDictionary *{
                return @{
                         @"ID" : @"id"
                         };
            }];
            
            NSArray *array=[ZCModel objectArrayWithKeyValuesArray:data[@"list"]];
            
            
            [self.datalist addObjectsFromArray:array];
            if (array.count<[Kpagesize integerValue]) {
                [self.tableView.footer noticeNoMoreData];
            }else{
                [self.tableView.footer resetNoMoreData];
            }
           
            [self.tableView reloadData];
           
        }
         [self.tableView.header endRefreshing];
    } failure:^(NSError *error) {
        [self.tableView.header endRefreshing];
    }];
}
-(void)loadmoredata{
    NSMutableDictionary *params=[NSMutableDictionary dictionary];
    
    if (self.isFromSearch) {
        if ([self.user_id integerValue]!=0) {
            params[@"type"]=@"person";
            params[@"user_id"]=self.user_id;
        }else{
            params[@"type"]=@"company";
            params[@"user_id"]=self.com_id;
        }
    }else{

    NSInteger power=[self.user.power integerValue];
    if (power<5) {
        params[@"type"]=@"person";
        params[@"user_id"]=self.user.user_id;
    }else{
        params[@"type"]=@"company";
        params[@"user_id"]=self.user.com_id;
        if (power==8) {
            params[@"pid"]=self.user.parent_id;
        }
    }
    }
    
    if (self.keyword) {
        params[@"keyword"]=self.keyword;
        if (self.cat_name) {
            params[@"cat_name"]=self.cat_name;
        }
        params[@"action"]=@"display_search";
    }else{
        if (self.brand_id) {
            params[@"brand_id"]=self.brand_id;
        }
        params[@"action"]=@"display_list";
    }

    
    params[@"num"]=Kpagesize;
    NSMutableArray *IDarray=[NSMutableArray array];
    
    for (ZCModel *mode in self.datalist) {
        [IDarray addObject:mode.ID];
    }
    params[@"page_id"]=[NSString DataTOjsonString:IDarray];
    
    [PostUitls Post:myzturl parameters:params success:^(id response) {
        
        NSDictionary *dict=response;
        NSNumber *state=dict[@"state"];
        if ([state integerValue]==400) {
            
            [ZCModel setupReplacedKeyFromPropertyName:^NSDictionary *{
                return @{
                         @"ID" : @"id"
                         };
            }];
            NSDictionary *data=dict[@"data"];
            NSArray *array=[ZCModel objectArrayWithKeyValuesArray:data[@"list"]];
            [self.datalist addObjectsFromArray:array];
            if (array.count<[Kpagesize integerValue]) {
                [self.tableView.footer noticeNoMoreData];
            }else{
                [self.tableView.footer resetNoMoreData];
            }
            
            [self.tableView reloadData];
            [self.tableView.footer endRefreshing];
        }else{
            [self.tableView.footer endRefreshing];
        }
        
    } failure:^(NSError *error) {
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        
        hud.labelText=@"网络错误";
        hud.mode = MBProgressHUDModeText;
        
        hud.margin = 10.f;
        
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
        [self.tableView.header endRefreshing];
    }];
}


-(void)setupsearch{
 
    CZSearchBar *search=[[CZSearchBar alloc]initWithFrame:CGRectMake(16, 16, XHScreenwidth-32, 30)];
    search.placeholder=@"可输入品牌、车型、车源类型、配置";
    search.background=[UIImage imageWithStretchableName:@"searchbar_textfield_background"];
    search.font=[UIFont systemFontOfSize:14];
    
    search.enabled=NO;
    UIButton *button=[[UIButton alloc]initWithFrame:search.frame];
    [button addTarget:self action:@selector(togosearch) forControlEvents:UIControlEventTouchUpInside];
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, XHScreenwidth, 56)];
    
    [view addSubview:search];
    [view addSubview:button];
    UIButton *clear=[[UIButton alloc]initWithFrame:CGRectMake(button.width-20, 7.5, 15, 15)];
    [clear setImage:[UIImage imageNamed:@"clearbtn"] forState:UIControlStateNormal];
    [clear addTarget:self action:@selector(clearsearch) forControlEvents:UIControlEventTouchUpInside];
    [button addSubview:clear];
    self.clearbtn=clear;
    self.search=search;
    self.tableView.tableHeaderView=view;
    self.search.text=self.keyword;
    if (self.keyword==nil) {
        self.clearbtn.hidden=YES;
            }else{
        self.clearbtn.hidden=NO;
    }

}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.tableView becomeFirstResponder];
}

-(UITableView *)tableView{
    if (_tableView==nil) {
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, XHScreenwidth, XHScreenheight) style:UITableViewStylePlain];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.backgroundColor=bgGarycolor;
        [self.view addSubview:_tableView];
    }
    return _tableView;
}
-(UIStatusBarStyle)preferredStatusBarStyle{
    return  _isshowsearch?UIStatusBarStyleDefault: UIStatusBarStyleLightContent;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)rightclick{
    _isedting=!_isedting;
    [self setupRight:_isedting];
    [self.tableView reloadData];
    
}
-(void)clearsearch{
    self.clearbtn.hidden=YES;
    self.search.text=nil;
    self.keyword=self.search.text;
    [self.tableView.header beginRefreshing];
    //        [self.searchController setActive:NO animated:YES];
    //        [self.searcharray removeAllObjects];
    
    
}
-(void)togosearch{
    _isshowsearch=YES;
    [self setNeedsStatusBarAppearanceUpdate];
    SearchTableViewController *searchvc=[SearchTableViewController viewController];
    searchvc.modalPresentationStyle=UIModalPresentationOverFullScreen;
    searchvc.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
    searchvc.delegate=self;
    searchvc.isFromZT=YES;
    NSMutableDictionary *params=[NSMutableDictionary dictionary];
    if (self.isFromSearch) {
        if ([self.user_id integerValue]!=0) {
            params[@"type"]=@"person";
            params[@"user_id"]=self.user_id;
        }else{
            params[@"type"]=@"company";
            params[@"user_id"]=self.com_id;
        }
    }else{
        
        
        NSInteger power=[self.user.power integerValue];
        
        if (power<5) {
            params[@"type"]=@"person";
            params[@"user_id"]=self.user.user_id;
        }else{
            params[@"type"]=@"company";
            params[@"user_id"]=self.user.com_id;
            //        if (power==8) {
            //            params[@"pid"]=self.user.parent_id;
            //        }
        }
    }

    searchvc.keywords=params;
    [self presentViewController:searchvc animated:YES completion:^{
        
    }];
    
}

-(void)setupRight:(BOOL)iseidting{
    if (iseidting) {
        UIBarButtonItem *rightitem=[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(rightclick)];
        [self.bottombar show];
        self.navigationItem.rightBarButtonItem=rightitem;
        
    }else{
        [self.bottombar hide];
        self.bottombar.allselected=NO;
        UIBarButtonItem *rightitem=[[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStyleDone target:self action:@selector(rightclick)];
        
        self.navigationItem.rightBarButtonItem=rightitem;
    }
    
    
}



-(BottomBar *)bottombar{
    if (_bottombar==nil) {
        _bottombar=[[BottomBar alloc]initWithBtnTitleArray:@[@"删除",@"刷新"] WithDelegate:self :YES];
        _bottombar.ishwopost=NO;
        _bottombar.datasource=self;
        [_bottombar addInView:self.view];
    }
    return _bottombar;
}

//-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
//    NSLog(@"%@",searchText);
//    if (searchText.length>0) {
//        if (![searchText isEqualToString:@"有限"]&&![searchText isEqualToString:@"公司"]&&![searchText isEqualToString:@"有限公"]&&![searchText isEqualToString:@"有限公司"]) {
//        NSMutableDictionary *params=[NSMutableDictionary dictionary];
//        if (self.isFromSearch) {
//            if ([self.user_id integerValue]!=0) {
//                params[@"type"]=@"person";
//                params[@"user_id"]=self.user_id;
//            }else{
//                params[@"type"]=@"company";
//                params[@"user_id"]=self.com_id;
//            }
//        }else{
//            
//            NSInteger power=[self.user.power integerValue];
//            
//            if (power<5) {
//                params[@"type"]=@"person";
//                params[@"user_id"]=self.user.user_id;
//            }else{
//                params[@"type"]=@"company";
//                params[@"user_id"]=self.user.com_id;
//                //        if (power==8) {
//                //            params[@"pid"]=self.user.parent_id;
//                //        }
//            }
//        }
//
//        params[@"keyword"]=searchText;
//        params[@"action"]=@"tips";
//                
//        [PostUitls Post:myzturl parameters:params success:^(id response) {
//            [self.searcharray removeAllObjects];
//            
//            NSDictionary *dict=response;
//            NSNumber *state=dict[@"state"];
//            if ([state integerValue]==400) {
//               NSArray *array=  [ZCSearchCount objectArrayWithKeyValuesArray:dict[@"data"]];
//                [self.searcharray addObjectsFromArray:array];
//                
//            }
//            
//            if (self.searcharray.count>0) {
//                
//                self.searchController.searchResultsTableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
//            }else{
//                self.searchController.searchResultsTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
//            }
//            
//            [self.searchController.searchResultsTableView reloadData];
//            
//        } failure:^(NSError *error) {
//            
//        }];
//        
//    }
//   }else{
//    
//    [self.searcharray removeAllObjects];
//    [self.searchController.searchResultsTableView reloadData];
//  }
//
//}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setupNav];
}
-(void)setupNav{
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}
     ];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbg"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setTranslucent:YES];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    if (tableView!=self.tableView) {
        
        return self.searcharray.count;
    }else{
        if (self.datalist.count==0) {
            self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        }else{
             self.tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
        }
        return self.datalist.count;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (tableView !=self.tableView) {
        ZCSearchCount *mode=self.searcharray[indexPath.row];
        SearchTableViewCell *cell=[SearchTableViewCell cellWithTablView:tableView];
        cell.name.text=mode.cat_name;
        cell.count.text=mode.count;
        return cell;
    }else{
       ZCModel *mode=self.datalist[indexPath. row];
       ZTCarTableViewCell *cell=[ZTCarTableViewCell cellWithTableView:tableView];
       cell.mode=mode;
       cell.isShowEidt=_isedting;
    
    return cell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (self.tableView !=tableView) {
        return 44;
    }else{
    
    return 112;
    }
}

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    self.keyword=searchBar.text;
    [self.searchController setActive:NO animated:YES];
    
    [self.tableView.header beginRefreshing];
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString

{
    
    for(UIView *subview in controller.searchResultsTableView.subviews) {
        
        if([subview isKindOfClass:[UILabel class]]) {
            
            [(UILabel*)subview setText:nil];
            
        }
        
    }
    return YES;
}

-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
    UITextField *searchBarTextField = nil;
    NSArray *views = ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) ? searchBar.subviews : [[searchBar.subviews objectAtIndex:0] subviews];
    for (UIView *subview in views)
    {
        if ([subview isKindOfClass:[UITextField class]])
        {
            searchBarTextField = (UITextField *)subview;
            break;
        }
    }
    searchBarTextField.enablesReturnKeyAutomatically = NO;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (self.tableView!=tableView) {
        ZCSearchCount *cout=self.searcharray[indexPath.row];
        self.keyword=self.searchController.searchBar.text;
        self.cat_name=cout.cat_name;
        [self.searchController setActive:NO animated:YES];
        
        [self.tableView.header beginRefreshing];
        
    }else{
    
    ZCModel *mode=self.datalist[indexPath.row];
    
    if (_isedting) {
       
        mode.ischecked=!mode.ischecked;
        ZTCarTableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];
        cell.editbutton.selected=!cell.editbutton.selected;
        
        for (ZCModel *carmode in self.datalist) {
            if (carmode.ischecked) {
                _candelete=YES;
                break;
            }else{
                _candelete=carmode.ischecked;
            }
        }
        self.bottombar.btnenable=_candelete;
    }else{
        MyZTCarDetailTableViewController *myztdvc=[MyZTCarDetailTableViewController Viewcontroller];
        myztdvc.isFromSearch=self.isFromSearch;
        myztdvc.ID=mode.ID;
        myztdvc.brand_logo=mode.brand_logo;
        self.keyword=nil;
        self.cat_name=nil;
        myztdvc.ztmode=self.ztmode;
        [self.navigationController pushViewController:myztdvc animated:YES];
    
    }
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
